var pageParam = {};

$(function() {
	$('#vue_vm_list div').hide();
});


function save() {
	view.data.leaseType = (view.data.leaseType==''? 0: parseInt(view.data.leaseType));
	view.data.totalRent = (view.data.totalRent==''? 0: parseFloat(view.data.totalRent));
	view.data.pledge = (view.data.pledge==''? 0: parseFloat(view.data.pledge));
	view.data.payWay = (view.data.payWay==''? 0: parseInt(view.data.payWay));
	view.data.leaseStatus = (view.data.leaseStatus==''? 0: parseInt(view.data.leaseStatus));

	save_basic(path+'/lease/save', {lease:view.data}, function() {
		alert('保存成功');
	});
}

function findAll() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();

	findAll_basic(path+'/lease/findAll', function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function findElder() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	var searchVal = $('#searchVal').val();
	
	find_basic(path+'/beHospitalFees/findElderInfo', searchVal, function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		if(response.data.length>0) {
			pageParam.elderId = response.data[0].elder.elderId;
			pageParam.elderName = response.data[0].elder.name;
			pageParam.buildingId = response.data[0].building.buildingId;
			pageParam.buildingName = response.data[0].building.buildingName;
			pageParam.floorId = response.data[0].floor.floorId;
			pageParam.floorName = response.data[0].floor.floorName;
			pageParam.roomNumber = response.data[0].room.roomNumber;
			pageParam.bedNumber = response.data[0].bed.bedNumber;
			pageParam.remindStatus = response.data[0].elderWalletForm.beStatus;
			pageParam.walletBalance = response.data[0].elderWalletForm.walletBalance;
		}
		
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function findLease() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	var searchVal = $('#searchVal').val();
	
	find_basic(path+'/lease/find', searchVal, function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getPayWayName:function(payWay) {
					var payWayName = '其他';
					
					switch(payWay) {
						case 1:
							payWayName = '现金';
							break;
						case 2:
							payWayName = '钱包扣费';
							break;
						case 3:
							payWayName = '五保免租金';
							break;
						case 4:
							payWayName = '五保免租金押金';
							break;
					}
					
					return payWayName;
				},
				
				lease_surrender:function(leaseForm) {
					if(response.data.length>0) {
						pageParam.elderId = response.data[0].elderForm.elderId;
						pageParam.elderName = response.data[0].elderForm.name;
						pageParam.buildingId = response.data[0].elderBeHospitalForm.buildingId;
						pageParam.buildingName = response.data[0].elderBeHospitalForm.buildingName;
						pageParam.floorId = response.data[0].elderBeHospitalForm.floorId;
						pageParam.floorName = response.data[0].elderBeHospitalForm.floorName;
						pageParam.roomNumber = response.data[0].elderBeHospitalForm.roomNumber;
						pageParam.bedNumber = response.data[0].elderBeHospitalForm.bedNumber;
						/*
						pageParam.remindStatus = response.data[0].elderWalletForm.beStatus;
						pageParam.walletBalance = response.data[0].elderWalletForm.walletBalance;
						*/
						pageParam.leaseForm = leaseForm;
					}
					
					save_basic_by_json(path+'/lease/surrender', {id:leaseForm.leaseId, returnMoney:0, payMoney:0}, function() {
						$('#' + leaseForm.leaseId + '_row').remove();
						alert('退租成功');
						window.location.href = '5-1-3tuizhu-1.html?pageParam=' + encodeURIComponent(JSON.stringify(pageParam));
					});
				}
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function goNextPage() {
	var url = '5-1-1ynrent-1.html?pageParam=' + encodeURIComponent(JSON.stringify(pageParam));
	window.open(url);
}

function deleteBatch() {
	deleteBatch_basic(path+'/lease/deleteBatch');
}
